#include "main.h"
/**
*@brief 
*@param
*@input
*@output
*/
uint8_t Checksum_Data(uint8_t *HexFrame)
{
	uint8_t i=0;
	uint8_t checksum=0;
	for(i=0;i<(SIZE_FRAME_HEX-1);i++)
	{
		checksum+=HexFrame[i];
	}
	checksum=(0xFF-(checksum&0xFF));
	
	if(checksum==HexFrame[SIZE_FRAME_HEX-1])
	{
		return 1;			/*OK*/
	}else
	{
		return 0;		/*Fail*/
	}
	
}

/**
  * @brief  Cover address from hexframe.
  * @param  HexFrame: Pointer to HexFrame contain data received
  * @retval Address
  */
uint32_t Cover_Address(uint8_t *HexFrame)
{
	uint32_t buff=0;
	buff=(uint32_t)HexFrame[4]|(((uint32_t)HexFrame[3])<<8)|(((uint32_t)HexFrame[2])<<16)|(((uint32_t)HexFrame[1])<<24);
	return buff;
}
void Cover_Data(uint8_t *HexFrame,uint8_t *Data)
{
	uint8_t i;	
	for(i=0;i<(SIZE_FRAME_HEX-1);i++)
	{
		Data[i]=HexFrame[i+5];/*put add data to add frame*/
	}
}
void Convert2Hex(uint8_t *Frame,uint8_t *HexFrame)
{
	uint8_t i,t;
	uint8_t hn,ln;
	
	for (i = 2,t=0; i < SIZE_FRAME; i+=2,t++) 
	{
		if(Frame[i]>'9')
		{
			hn=Frame[i] - 'A' + 10;
		}else
		{
			hn=Frame[i]-'0';
		}
		/*=============================================*/
		if(Frame[i+1]>'9')
		{
			ln=Frame[i+1] - 'A' + 10;
		}else
		{
			ln=Frame[i+1]-'0';
		}
		HexFrame[t]= (hn << 4 ) | ln;
	}
}

uint32_t Cover_AmountHex_Frame(uint8_t *HexFrame)
{
	uint32_t Result=0;
	Result=(uint32_t)HexFrame[SIZE_FRAME_HEX-2]|(((uint32_t)HexFrame[SIZE_FRAME_HEX-3])<<8);
	return Result;
}
